package pl.drypisy;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

/**
 * main app menu
 * btn -> routeListActv
 * btn for resuming last game
 * btn -> browserActv
 * btn -> exit app
 * @author Michal Drobniak
 */
public class MenuActivity extends Activity {

	//stałe do Shared preferences
    private final String PREF_NAME = "Prefs";
    private final String PREF_CHP = "chid";
    private final String PREF_ROUTE = "rid";
    private Button resumeGameBtn;
    
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.menu);        
        
        Button startGameBtn=(Button) findViewById(R.id.startRouteBtn);
        startGameBtn.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				startActivity(new Intent("pl.drypisy.RouteListActivity"));
			}
		});
        
        resumeGameBtn=(Button) findViewById(R.id.resumeRouteBtn);
        resumeGameBtn.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				//intencja
				Intent map = new Intent(getBaseContext(), PlayMapActivity.class);
				startActivity(map);
			}
		});
        
        Button browseGamesBtn=(Button) findViewById(R.id.browseRouteBtn);
        browseGamesBtn.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				startActivity(new Intent("pl.drypisy.BrowserActivity"));
			}
		});
        
        Button exitBtn=(Button) findViewById(R.id.exitBtn);
        exitBtn.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				finish();
			}
		});
    }
    
    //musi być w on resume, bo zakładamy sytuacje: ktoś skończył gre i wraca do menu activity i... może kliknać 'wznów gre' bo zostało to z onCreate. A tak onResume pokazuje się przy każdorazowym wyświetleniu
    @Override
    public void onResume(){
    	super.onResume();
    	//pobieranie shared preferences
        SharedPreferences pref = getSharedPreferences(PREF_NAME, MODE_PRIVATE);
    	//jeśli nie ma czego wznawiać to schowaj
    	if (pref.contains(PREF_CHP)){
        	resumeGameBtn.setEnabled(true);
    	}
    	else {
    		resumeGameBtn.setTextColor(R.color.inactiveBtn);
    		resumeGameBtn.setEnabled(false);
    	}
    }
}